﻿/* 
 * DiagnosticsDesign.cs
 * 
 * Author - Ankit Gupta and Gaurav Aggarwal
 * 
 * This file handles component design of Diagnostics tab.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using Microsoft.Win32;

partial class DiagnosticsControl
{
    public GroupBox grpbox = new GroupBox();
    public Label enableTracingLabel = new Label();
    public Label traceAsDebugOutputLabel = new Label();
    public Label logEntriesLabel = new Label();
    public Label logSizeLabel = new Label();
    public Label kBLabel = new Label();
    public Label reportStartupLabel = new Label();
    public Label breakpointOnPanicLabel = new Label();  
    public Label signatureVerificationLabel = new Label();
    public Label debugCallsLabel = new Label();
    public TextBox logEntriesTextBox = new TextBox();
    public TextBox logSizeTextBox = new TextBox();
    public CheckBox enableTracingCheckBox = new CheckBox();
    public CheckBox traceAsDebugOutputCheckBox = new CheckBox();
    public CheckBox reportStartupCheckBox = new CheckBox();
    public CheckBox breakpointOnPanicCheckBox = new CheckBox();
    public CheckBox signatureVerificationCheckBox = new CheckBox();
    public CheckBox debugCallsCheckBox = new CheckBox();
    public Button applyButton = new Button();
    public Button cancelButton = new Button();

    RegistryKey serviceParameters = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", true);
    RegistryKey clientParameters = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client", true);

    public DiagnosticsControl()
    {
        grpbox.Location = new System.Drawing.Point(20, 10);
        grpbox.Name = "grpBox";
        grpbox.Size = new System.Drawing.Size(550, 190);
        grpbox.Text = "Tracing";

        // Enable/Disable logging trace output
        enableTracingCheckBox.Location = new System.Drawing.Point(25, 27);
        enableTracingCheckBox.Name = "enableTracingCheckBox";
        enableTracingCheckBox.Size = new System.Drawing.Size(15, 20);
        enableTracingCheckBox.Checked = Convert.ToBoolean(((int)serviceParameters.GetValue("TraceOption", 0) & 8) >> 3);

        enableTracingLabel.Location = new System.Drawing.Point(40, 30);
        enableTracingLabel.Name = "enableTracingLabel";
        enableTracingLabel.Size = new System.Drawing.Size(200, 15);
        enableTracingLabel.Text = "Enable logging trace output";

        // Send trace as debug output
        traceAsDebugOutputCheckBox.Location = new System.Drawing.Point(55, 57);
        traceAsDebugOutputCheckBox.Name = "traceAsDebugOutputCheckBox";
        traceAsDebugOutputCheckBox.Size = new System.Drawing.Size(20, 20);
        traceAsDebugOutputCheckBox.Checked = Convert.ToBoolean(((int)serviceParameters.GetValue("TraceOption", 0) & 4) >> 2);

        traceAsDebugOutputLabel.Location = new System.Drawing.Point(75, 60);
        traceAsDebugOutputLabel.Name = "traceAsDebugOutputLabel";
        traceAsDebugOutputLabel.Size = new System.Drawing.Size(160, 15);
        traceAsDebugOutputLabel.Text = "Send trace as debug output";

        // Number of enteries to keep in log
        logEntriesLabel.Location = new System.Drawing.Point(55, 94);
        logEntriesLabel.Name = "logEntriesLabel";
        logEntriesLabel.Size = new System.Drawing.Size(200, 15);
        logEntriesLabel.Text = "Number of enteries to keep in log";

        logEntriesTextBox.Location = new System.Drawing.Point(265, 90);
        logEntriesTextBox.Name = "logEntriesTextBox";
        logEntriesTextBox.Size = new System.Drawing.Size(240, 20);
        logEntriesTextBox.Text = ((int)serviceParameters.GetValue("TraceBufferSize", 5000)).ToString();

        // Maximum Size of lo file
        logSizeLabel.Location = new System.Drawing.Point(55, 134);
        logSizeLabel.Name = "logSizeLabel";
        logSizeLabel.Size = new System.Drawing.Size(200, 15);
        logSizeLabel.Text = "Maximum Size of log file";

        logSizeTextBox.Location = new System.Drawing.Point(265, 130);
        logSizeTextBox.Name = "logSizeTextBox";
        logSizeTextBox.Size = new System.Drawing.Size(240, 20);
        logSizeTextBox.Text = ((int)serviceParameters.GetValue("MaxLogSize", 100)).ToString();

        kBLabel.Location = new System.Drawing.Point(510, 133);
        kBLabel.Name = "kBLabel";
        kBLabel.Size = new System.Drawing.Size(20, 15);
        kBLabel.Text = "kB";

        // Report each SMB session startup in the application eventlog
        reportStartupCheckBox.Location = new System.Drawing.Point(25, 172);
        reportStartupCheckBox.Name = "reportStartupCheckBox";
        reportStartupCheckBox.Size = new System.Drawing.Size(15, 20);
        reportStartupCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("ReportSessionStartups", 0));

        reportStartupLabel.Location = new System.Drawing.Point(40, 175);
        reportStartupLabel.Name = "reportStartup";
        reportStartupLabel.Size = new System.Drawing.Size(350, 15);
        reportStartupLabel.Text = "Report each SMB session startup in the application eventlog";

        // Issue a debug breakpoint in the event of a panic
        breakpointOnPanicCheckBox.Location = new System.Drawing.Point(20, 227);
        breakpointOnPanicCheckBox.Name = "breakpointOnPanicCheckBox";
        breakpointOnPanicCheckBox.Size = new System.Drawing.Size(20, 20);
        breakpointOnPanicCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("TrapOnPanic", 0));

        breakpointOnPanicLabel.Location = new System.Drawing.Point(40, 230);
        breakpointOnPanicLabel.Name = "breakpointOnPanicLabel";
        breakpointOnPanicLabel.Size = new System.Drawing.Size(250, 15);
        breakpointOnPanicLabel.Text = "Issue a debug breakpoint in the event of a panic";

        // Verify signatures of service binaries
        signatureVerificationCheckBox.Location = new System.Drawing.Point(20, 277);
        signatureVerificationCheckBox.Name = "signatureVerificationCheckBox";
        signatureVerificationCheckBox.Size = new System.Drawing.Size(20, 20);
        signatureVerificationCheckBox.Checked = Convert.ToBoolean((int)clientParameters.GetValue("VerifyServiceSignature", 1));

        signatureVerificationLabel.Location = new System.Drawing.Point(40, 280);
        signatureVerificationLabel.Name = "signatureVerificationLabel";
        signatureVerificationLabel.Size = new System.Drawing.Size(250, 15);
        signatureVerificationLabel.Text = "Verify signatures of service binaries";

        // Debug AFS IOCTL calls
        debugCallsCheckBox.Location = new System.Drawing.Point(20, 327);
        debugCallsCheckBox.Name = "debugCallsCheckBox";
        debugCallsCheckBox.Size = new System.Drawing.Size(20, 20);
        debugCallsCheckBox.Checked = Convert.ToBoolean((int)clientParameters.GetValue("IoctlDebug", 0));

        debugCallsLabel.Location = new System.Drawing.Point(40, 330);
        debugCallsLabel.Name = "debugCallsLabel";
        debugCallsLabel.Size = new System.Drawing.Size(250, 15);
        debugCallsLabel.Text = "Debug AFS IOCTL calls";

        applyButton.Location = new System.Drawing.Point(20, 460);
        applyButton.Name = "applyButton";
        applyButton.Size = new System.Drawing.Size(100, 23);
        applyButton.Text = "Apply";
        applyButton.Click += new System.EventHandler(applyButton_Click);

        cancelButton.Location = new System.Drawing.Point(140, 460);
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(100, 23);
        cancelButton.Text = "Cancel";
        cancelButton.Click += new System.EventHandler(cancelButton_Click);
    }

    private void resetButton_Click(object sender, EventArgs e)
    {

    }

    private void saveButton_Click(object sender, EventArgs e)
    {

    }
}